#!/usr/bin/env node
"use strict";
import chalk from "chalk";
import { prompt } from "enquirer";

import { version } from "../package.json";

import fs from "fs-extra";
import sade from "sade";
import { res_T } from "./types";
import { findItemByKey, scriptMeta } from "./script";
import figlet from 'figlet'
import ora from "ora"
import { execa } from "execa";
import { deleteGitFolder } from "./utils";

const spinner = ora("Loading unicorns");




const prog = sade("w-cli");
console.log(figlet.textSync('FreeDom Is Everything!', {
    font: 'Ghost',
    horizontalLayout: 'default',
    verticalLayout: 'default',
    width: 150,
    whitespaceBreak: true
}));
prog.version(version);

// python3项目
prog
    .command("py")
    .option("-version")
    .describe("create project")
    .example("w-cli py")
    .action(async (arag) => {
        // console.log(arag, 11);

        // const { username }: res_T = await prompt({
        //     type: "input",
        //     name: "username",
        //     message: "what is you name?",
        // });
        spinner.start();
        spinner.color = "yellow";
        spinner.text = "Loading rainbows";
        execa('git', ['clone', 'https://gitee.com/brother-linghu/w-python-demo.git'], { cwd: './' }).then(() => {
            deleteGitFolder('./w-python-demo')
            spinner.succeed();
        })
    });
// node脚本
prog
    .command("node")
    .option("-version")
    .describe("create project")
    .example("w-cli node")
    .action(async (arag) => {
        // console.log(arag, 11);

        // const { projectname }: res_T = await prompt({
        //     type: "input",
        //     name: "projectname",
        //     message: "what is you name?",
        // });
        spinner.start();
        spinner.color = "yellow";
        spinner.text = "Loading rainbows";
        execa('git', ['clone', 'https://gitee.com/brother-linghu/w-node-demo.git'], { cwd: './' }).then(() => {
            deleteGitFolder('./w-node-demo')
            spinner.succeed();
        })
    });
// 小程序
prog
    .command("miniapp")
    .option("-version")
    .describe("create project")
    .example("w-cli miniapp")
    .action(async (arag) => {
        // console.log(arag, 11);

        // const { projectname }: res_T = await prompt({
        //     type: "input",
        //     name: "projectname",
        //     message: "what is you name?",
        // });
        spinner.start();
        spinner.color = "yellow";
        spinner.text = "Loading rainbows";
        execa('git', ['clone', 'https://gitee.com/brother-linghu/w-miniapp-demo.git'], { cwd: './' }).then(() => {
            deleteGitFolder('./w-miniapp-demo')
            spinner.succeed();
        })
    });
//next服务端渲染项目
prog
    .command("next")
    .option("-version")
    .describe("create project")
    .example("w-cli miniapp")
    .action(async (arag) => {
        // console.log(arag, 11);

        // const { projectname }: res_T = await prompt({
        //     type: "input",
        //     name: "projectname",
        //     message: "what is you name?",
        // });git clone https://gitee.com/brother-linghu/w-next-demo.git
        spinner.start();
        spinner.color = "yellow";
        spinner.text = "Loading rainbows";
        execa('git', ['clone', 'https://gitee.com/brother-linghu/w-next-demo.git'], { cwd: './' }).then(() => {
            deleteGitFolder('./w-miniapp-demo')
            spinner.succeed();
        })
    });
prog.parse(process.argv);
